<?php
class MovimentacaoDAO{

	private $tableName = 'tb_movimentacao';
	private $conn;
	private $sqlGenerator;
	private $prefixo;


	public function __construct(){

		$this->conn  = new CONEXAO();

	}

	public function getTableName(){
		return $this->tableName;
	}

	public function setTableName($tableName){
		$this->tableName=$tableName;
	}

	public function getConn(){
		return $this->conn;
	}

	public function setConn($conn){
		$this->conn=$conn;
	}

	public function getSqlGenerator(){
		return $this->sqlGenerator;
	}

	public function setSqlGenerator($sqlGenerator){
		$this->sqlGenerator=$sqlGenerator;
	}

	public function getPrefixo(){
		return $this->prefixo;
	}

	public function setPrefixo($prefixo){
		$this->prefixo=$prefixo;
	}

	public function mapear(){

		$array = $obj->toArray();
		
		$this->conn->Conecta();
		
		if(!isset($array['id']) || $array['id']==0){
			$array['id'] = $this->conn->maxId($this->tableName,$this->prefixo) + 1;
		}
		$this->conn->Desconecta();
		
		return $array;

	}

	public function inserir($obj){

		if(!$obj instanceof Movimentacao){
		
			throw(new Exception("Dados Inapropriados"));
		}
		
		$tableName = $this->tableName;
		
		
		$comando = DMLGenerator::createInsert($tableName,$this->mapear($obj),$this->prefixo);
		
		$this->conn->Conecta();
		$this->conn->Executa($comando);
		$this->conn->Desconecta();
		
		return true;
	}

	public function atualizar($obj){

		if(!$obj instanceof Movimentacao){
	 	
	 		throw(new Exception("Dados Inapropriados"));
	 	}
	 	
	 	$tableName = $this->tableName;
	 	
	 	
	 	$comando = DMLGenerator::createUpdate($tableName,$this->mapear($obj),$this->prefixo);
	 	
	 	$this->conn->Conecta();
	 	$this->conn->Executa($comando);
	 	$this->conn->Desconecta();

	}

	public function apagar($obj){

		if(!$obj instanceof Movimentacao){
		
			throw(new Exception("Dados Inapropriados"));
		}
		
		$tableName = $this->tableName;
		
		
		$comando = DMLGenerator::createDelete($tableName,$obj->getId(),$this->prefixo);
		
		$this->conn->Conecta();
		$this->conn->Executa($comando);
		$this->conn->Desconecta();

	}

	public function geraWherePesquisa(){

		//TODO

	}

	public function contem(){

		//TODO

	}

	public function buscar(){

		//TODO

	}

	public function buscarTodos(){

		//TODO

	}

	public function buscarTodosSerach(){

		//TODO

	}

}

?>